const 
    crypto = require('crypto'),
    { cryptoSecret } = require('../config/config');

function makeCrypto(str) {
    const _md5 = crypto.createHash('md5'),
        content = `str=${str}&secret=${cryptoSecret}`;
    return _md5.update(content).digest('hex')
}
function trimSpace(str) {
    return str.replace(/\s+/g, '');
}
function returnInfo(errorInfo, data) {
    if (data) {
        errorInfo.data = data
    }
    return errorInfo
}
function fileUploadLegel(ctx) {
    if (!ctx.request.files) {
        return false;
    }
    let files = Object.entries(ctx.request.files);
    if (!files.length > 0) {
        return false;
    }
    if (!files[0][1].name) {
        return false;
    }
    return true;

}
// function 
module.exports = {
    makeCrypto,
    trimSpace,
    returnInfo,
    fileUploadLegel
}     